<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/includes.jsp" %>
<html>
 <head>
    <title>盘点任务管理</title>
    <!-- import css and js -->
	<%@ include file="/common/meta.jsp" %>
	<script src="${ctx}/js/ligerUI/js/plugins/ligerLayout.js" type="text/javascript"></script>
	<script src="${ctx}/js/jsp/comm.js" type="text/javascript"></script>
	<script type="text/javascript">
		var basic_Url="${ctx}/yd/logic/whcheckmission";
		var basic_WUrl="yd/logic/whcheckmission";
		var basic_Title="盘点任务管理";
		var show_Width=1000;
		var show_Hight=500;
		var grid;
		function createSearch(){
			init(1,8,'60,120,60,100,60,100,60,100','10%');
			//第一行的数据
			addCommon(0,0,"lable","单据编号：");
			addCommon(0,1,"txtlike","zd002TackCode");
			addCommon(0,2,"lable","盘点仓库：");
			addCommon(0,3,"selectEnum","zd001WhName","<option></option><c:forEach var="s" items="${wh}"><option value='${s.name}'>${s.name}</option></c:forEach>");
			addCommon(0,4,"lable","制单人：");
			addCommon(0,5,"txtlike","bizCreatorName");
			addCommon(0,6,"lable","单据状态");
 			addCommon(0,7,"selectEnum","zd003BillStatus","<option></option><c:forEach var="status" items="${checkStatus}"><option value='${status.value}'>${status.desc}</option></c:forEach>");
		}
		
		function searchAP(){
			multipleSearch("#table1",true,"",basic_Url+"/list.do");
		}
		
		function addpd(){
			var url = basic_WUrl+"/operate/add/0.do";
			
			ShowIframeDialog("operate",basic_Title,url,show_Width,show_Hight);
		}
		
		$(function(){
			grid = $("#table1").ligerGrid({
		        columns: [
		                  { display: '单据编号', name: 'zd002TackCode', width: 180 ,enabledEdit:true},
		                  { display: '盘点仓库', name: 'zd001WhName', width: 100},
		                  { display: '制单人', name: 'bizCreatorName', width: 80},
		                  { display: '盘点人', name: 'zd004Agent', width:80},
		                  { display: '单据状态', name: 'zd003BillStatus', width: 50,
		                	  render: function (item){
		                		  var billStatus=item.zd003BillStatus;
		                		  if(billStatus=="0"){
		                			  return "草稿";
		                		  }if(billStatus=="1"){
		                			  return "未盘点";
		                		  }if(billStatus=="2"){
		                			  return "盘点中";
		                		  }if(billStatus=="3"){
		                			  return "审核中";
		                		  }if(billStatus=="4"){
		                			  return "已完结";
		                		  }if(billStatus=="5"){
		                			  return "驳回重盘";
		                		  }
		                	  }},
		                  { display: '创建时间', name: 'bizCreatorDate', width: 180,
		                	  render: function (item){
		                		  var cdate=new Date(item.bizCreatorDate);
		                		  return formatDate(cdate,"yyyy-MM-dd");
		                	  }}
		                  ],
		                  enabledEdit: true,
		                  usePager: true, rownumbers: true, 
		                  pageSize:15,
		                  pageSizeOptions :[15,25,35],
		                  url:basic_Url+"/list.do?checkTask=${checkTask}",
		                  width: "100%", height:'100%', checkbox: true, 
		                  enabledSort:false,
	                      onDblClickRow : function (data, rowindex, rowobj){
	                    		var url=basic_WUrl+"/operate/edit/"+data.id+".do?checkTask=${checkTask}";
	                    		ShowIframeDialog("operate",basic_Title,url,show_Width,show_Hight);
	                       }
		                  });
			$("#pageloading").hide();
			});
		
		function checkdel(){
			var manager = $("#table1").ligerGetGridManager(); 
			var rows =manager.getSelectedRows();
			var bol = false;
			if (rows==null || 0 == rows.length){
					$.dialog.alert('请选择需要操作删除的行！');
					return;
			}
			for(var i=0;i<rows.length;i++){
			 	if (rows[i].bizCreatorName != "${user.name}"){
			 		bol = true;
				}
			}
			if(bol){
				$.dialog.alert('请选择自己创建的草稿单据进行删除操作!');
				return;
			}else{
				bol = false;
				for(var i=0;i<rows.length;i++){
				 	if (rows[i].zd003BillStatus>0){
				 		bol = true;
					}
				}
				if(bol){
					$.dialog.alert('非草稿状态的单据不能删除!');
					return;
				}else{
					del();
					bol = false;
				}
			}	
		}

		$(function(){
			if('${checkTask}'=='select'){
				$("#add").hide();
				$("#del").hide();
			}else if('${checkTask}'=='noselect'){
				$("#check").hide();
			}else if('${checkTask}'=='check'){
				$("#add").hide();
				$("#del").hide();
				$("#check").hide();
			}
		});
		function check(){
			var arr="";
			var manager = $("#table1").ligerGetGridManager(); 
			var rows =manager.getSelectedRows();
			for(var i=0;i<rows.length;i++){
				if(arr==""){
		 			arr=rows[i].id;
		 		}else{
		 			arr=arr+","+rows[i].id;
		 		}
			}
			var url=basic_WUrl+"/check.do?data="+arr;
			ShowIframeDialogMax("operate","盘点任务单",url,show_Width,show_Hight);

		}
	</script>
	 
  </head>
 <body style="padding:10px" onload="createSearch()">  
       <div id="layout1">
          <div class="panelBar">
	            <ul class="toolBar">
		           <li><a class="add" onclick="addpd()" id="add"><span>新增</span></a></li>
				   <li><a class="delete" onclick="checkdel()" id="del"><span>删除</span></a></li>
				   <li><a class="add" onclick="check()" id="check"><span>去盘点</span></a></li>
               </ul>
          </div>
          <div id="pageHeader" class="pageHeader">
               <div class="searchBar" id="multipleSearchDialog">
	                <table class="table" width="100%" id="searchHeader" >  
                        <tbody id="newbody">
                        </tbody>
 	                </table>
                    <div class="subBar">
			             <ul>
				             <li><div class="buttonActive"><div class="buttonContent"><button type="submit" id="btnSearch" onclick="searchAP()">查询</button></div></div></li>
				             <li><a class="button" onclick="clearSearch()"><span>重置</span></a></li>
			             </ul>
	                </div>
               </div>
          </div>
      </div>
      <div position="center" id="table1">
      </div>
      <div class="clear"></div>
    </body>
</html>